﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using Srvtools;

public partial class SingleSignOn : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        string url = Request.Params["RedirectUrl"];
        string key = Request.Params["PublicKey"];

        string[] ss = key.Split(":".ToCharArray());
        string k = ss[0];

            if (PublicKey.CheckPublicKey(k) && url.Length != 0)
            {
                string[] ss1 = ss[0].Split("-".ToCharArray());
                CliUtils.fClientSystem = "Web";
                CliUtils.fLoginUser = ss1[0];
                CliUtils.fLoginDB = ss1[1];
                CliUtils.fCurrentProject = ss1[2];
                CliUtils.fComputerIp = Request.UserHostAddress;
                CliUtils.fComputerName = Request.UserHostName;
                string[] langs = Request.UserLanguages;
                if (string.Compare(langs[0], "zh-cn", true) == 0)//IgnoreCase
                {
                    CliUtils.fClientLang = SYS_LANGUAGE.SIM;
                }
                else if (string.Compare(langs[0].ToLower(), "zh-tw", true) == 0)//IgnoreCase
                {
                    CliUtils.fClientLang = SYS_LANGUAGE.TRA;
                }
                else
                {
                    CliUtils.fClientLang = SYS_LANGUAGE.ENG;
                }

                string[] ss2 = ss[1].Split("-".ToCharArray());
                CliUtils.fUserName = ss2[0];
                if (ss2.Length == 2)
                {
                    CliUtils.fGroupID = ss2[1];
                }

                Response.Redirect(url);
            }
            else
            {
                throw new Exception("PublishKey is error or url is null.");

            }
        }
}
